<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="../utils/jquery3-7-1.js"></script>
    <title>Document</title>
  </head>
  <body>
    <button id="login">login</button>
    <button id="nologin">nologin</button>
  </body>
  <script>
    $(function () {
      let token = "";
      $("#login").click(() => {
        $.ajax({
          type: "post",
          url: "http://127.0.0.1:80/api/login",
          data: { username: "admin", password: "123" },
          success: (res) => {
            console.log(res);
            token = res.token;
          },
        });
      });

      $("#nologin").click(() => {
        $.ajax({
          type: "post",
          url: "http://127.0.0.1:80/nologin",
          //携带加密的token 标识已登录 header paload signature
          beforeSend: function (request) {
            request.setRequestHeader("Authorization", "Bearer" + " " + token);
          },
          success: (res) => {
            console.log(res);
          },
        });
      });
    });
  </script>
</html>
